package AutoDiary;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;


public class FileUploadClient {
    public String uploadData() throws Exception{
       	HttpClient httpclient = new DefaultHttpClient();
        String responseBody = null;
        try {
            //HttpGet httpget = new HttpGet("http://homepage.cs.latrobe.edu.au/mtdo/servlet/FileUploadServlet");

            List<NameValuePair> qparams = new ArrayList<NameValuePair>();
            qparams.add(new BasicNameValuePair("q", "httpclient"));
            qparams.add(new BasicNameValuePair("oq", null));
            URI uri = URIUtils.createURI("http", "homepage.cs.latrobe.edu.au", -1, "/mtdo/servlet/FileUploadServlet", 
                URLEncodedUtils.format(qparams, "UTF-8"), null);
            HttpGet httpget = new HttpGet(uri);
           
            System.out.println("executing request " + httpget.getURI());

            // Create a response handler
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            responseBody = httpclient.execute(httpget, responseHandler);
            System.out.println("----------------------------------------");
            System.out.println(responseBody);
            System.out.println("----------------------------------------");
            

        } finally {
            // When HttpClient instance is no longer needed,
            // shut down the connection manager to ensure
            // immediate deallocation of all system resources
            httpclient.getConnectionManager().shutdown();
        }
        return responseBody;
    }
        
}
